<?php
declare(strict_types=1);

if (extension_loaded("swoole")) {
    if (version_compare(SWOOLE_VERSION, '5.0.1', '>=') == false) {
        exit("swoole扩展版本必须大于等于5.0.1\n");
    }
} else {
    exit("必须安装swoole扩展\n");
}

if (version_compare(PHP_VERSION, '8.0.0', '>=') == false) {
    exit("PHP版本必须大于等于8.0.0\n");
}
if (function_exists('opcache_reset')) {
    opcache_reset();
}

define('__COMDIR__', __ROTDIR__ . 'Common/');
define('__VENDIR__', __ROTDIR__ . 'vendor/');
define('__APPDIR__', __ROTDIR__ . 'App/');
define('__PUBDIR__', __APPDIR__ . 'Helper/');
define('__PLUDIR__', __APPDIR__ . 'Plugin/');

define('__PIDDIR__', __ROTDIR__ . 'Pid/');

define('__CAHDIR__', __ROTDIR__ . 'Cache/');
define('__IDEDIR__', __CAHDIR__ . 'Ide/');//给IDE使用
define('__LOGDIR__', __CAHDIR__ . 'Log/');//日志
define('__STADIR__', __CAHDIR__ . 'Stat/');//统计

define('__FDADIR__', __APPDIR__ . 'Field/');



define('__PHPATH__', PHP_BINARY);

if (PHP_OS != 'Darwin' ) {
    define('__TMPDIR__', '/dev/shm/' . md5(__DIR__) . '/');
} else {
    define('__TMPDIR__', __ROTDIR__ . 'Tmp/');
}
!is_dir(__PIDDIR__) and mkdir(__PIDDIR__, 0777, true) && chmod(__PIDDIR__, 0777);
!is_dir(__STADIR__) and mkdir(__STADIR__, 0777, true) && chmod(__STADIR__, 0777);
!is_dir(__TMPDIR__) and mkdir(__TMPDIR__, 0777, true) && chmod(__TMPDIR__, 0777);
!is_dir(__TMPDIR__ . 'pid') and mkdir(__TMPDIR__ . 'pid', 0777, true) && chmod(__TMPDIR__ . 'pid', 0777);
!is_dir(__IDEDIR__) and mkdir(__IDEDIR__, 0777, true) && chmod(__IDEDIR__, 0777);
!is_dir(__CAHDIR__ . 'Service/') && mkdir(__CAHDIR__ . 'Service/', 0777, true) && chmod(__CAHDIR__ . 'Service/', 0777);

include_once __VENDIR__ . 'autoload.php';

$func = glob(__CFRDIR__ . 'Func/*.php');
foreach ($func as $_file) {
    include_once $_file;
}
$pool = glob(__CFRDIR__ . 'Pool/*.php');
foreach ($pool as $_file) {
    include_once $_file;
}

$class = glob(__CFRDIR__ . 'Support/*.php');
foreach ($class as $_file) {
    include_once $_file;
}

plugin_clear_tmp_dir();

plugin_init();//插件初始化

plugin_get_hook();

include_once _include(__CFRDIR__ . 'Process.php');
include_once _include(__CFRDIR__ . 'Service.php');
